<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html lang="en">
<head>
	<%@include file="/WEB-INF/jsp/qsws/commons/head.jsp"%>
    <link rel="stylesheet" type="text/css" href="resources/qsws/css/teacher.css">
	<script src="resources/qsws/js/index.js" type="text/javascript"></script>
	<script type="text/javascript">
		$(function(){
			var teacherUrl = "qsws/teacher?teacherId=" + ${teacherId};
			var coursesOfTeacherUrl = "qsws/coursesOfTeacher?teacherId=" + ${teacherId};
			$.getJSON(teacherUrl,function(data){
				if(data.teacher != null){
					$('header p').text('讲师：' + data.teacher.name);
					$('.msg p').text(data.teacher.intro);
				}
			});
			$.getJSON(coursesOfTeacherUrl,function(data){
				var courses = data.courseList;
				if(courses != null){
					$a = $('.courses a').first();
					for(var i in courses){
						$aClone = $a.clone();
						$aClone.attr('href','');
						$aClone.find('.courseImg').attr('src',courses[i].middle_img)
						syncAjaxPost('api/course/getCourseCategory', {"courseId" : courses[i].id}, function(data2){
							$aClone.find('.tag').text(data2.courseCategory?data2.courseCategory.name:'暂无');
						});
						$aClone.find('.title').text(courses[i].name);
						syncAjaxPost('api/course/getCourseMetadata', {"courseId" : courses[i].id}, function(data2){
							$aClone.find('.xs').text('学时：' + (data2.courseMetadata ? data2.courseMetadata.period : 0.0));
						});
						syncAjaxPost('api/courseCount/findCourseCountByCourseId', {"courseId" : courses[i].id}, function(data2){
							$aClone.find('.rs').text(data2.courseCount ? data2.courseCount.study_num : 0);
						});
						$aClone.show();
						$('.courses').append($aClone);
					}
				}
			});
		});
		function syncAjaxPost(url, sendedData, fun) {
		$.ajax({
			type : "POST",
			url : url,
			data : sendedData,
			async : false,
			success : function(receiveData) {
				fun(receiveData);
			}
		});
	}
	</script>
</head>
<body>
	<!-- 头部 -->
	<header>
		<img src="resources/qsws/img/people6.jpg" alt="">
		<p></p>
	</header>
	<!-- 内容 -->
	<section>
		<div class="btn">
			<a href="javascript:;" class="curr">讲师简介</a>
			<span></span>
			<a href="javascript:;">视频课程</a>
		</div>
		<div>
			<div class="msg">
				<p></p>
			</div>
			<ul class="hide courses">
					<a href="" style="display:none;"><li class="clearfix">
						<div class="img l">
							<img class="courseImg" onerror="this.src='resources/qsws/img/kecheng.jpg'" alt="">
							<p class="tag"></p>
						</div>
						<div class="words r">
							<p class="title ell"></p>
							<!-- <p class="msg ell">给想抓住未来机会的聪明人</p> -->
							<p class="xueshi"><span class="xs"></span><span class="rs"></span></p>	
						</div>
					</li></a>
			</ul>
		</div>
	</section>	
</body>
<script>
	$('.btn a').click(function(){
		var _index = $(this).index('a');
		$(this).addClass('curr').siblings('a').removeClass('curr');
		$(this).parent().siblings().children().eq(_index).show().siblings().hide();
	})
</script>
</html>